import type { PageParam, PageResult } from '@vben/request';
import type { Dayjs } from 'dayjs';

import { requestClient } from '#/api/request';

export namespace CommissionSettlementApi {
  /** 提成结算信息 */
  export interface CommissionSettlement {
    id: number; // 主键ID
    settlementCode?: string; // 结算编码
    staffId?: number; // 员工ID
    settlementPeriod?: string; // 结算周期(YYYY-MM)
    totalCommission?: number; // 总提成金额
    totalBonus: number; // 总奖励金额
    totalAmount?: number; // 结算总金额
    recordCount?: number; // 记录数量
    status: string; // 状态
    confirmTime: string | Dayjs; // 确认时间
    payTime: string | Dayjs; // 发放时间
    paymentMethod: string; // 支付方式
    paymentReference: string; // 支付凭证
    staffType?: string; // 员工类型
    serviceCommission: number; // 服务类提成金额
    salesCommission: number; // 销售类提成金额
    referralCommission: number; // 推荐/分销类提成金额
  }
}

/** 查询提成结算分页 */
export function getCommissionSettlementPage(params: PageParam) {
  return requestClient.get<PageResult<CommissionSettlementApi.CommissionSettlement>>('/spa/commission-settlement/page', { params });
}

/** 查询提成结算详情 */
export function getCommissionSettlement(id: number) {
  return requestClient.get<CommissionSettlementApi.CommissionSettlement>(`/spa/commission-settlement/get?id=${id}`);
}

/** 新增提成结算 */
export function createCommissionSettlement(data: CommissionSettlementApi.CommissionSettlement) {
  return requestClient.post('/spa/commission-settlement/create', data);
}

/** 修改提成结算 */
export function updateCommissionSettlement(data: CommissionSettlementApi.CommissionSettlement) {
  return requestClient.put('/spa/commission-settlement/update', data);
}

/** 删除提成结算 */
export function deleteCommissionSettlement(id: number) {
  return requestClient.delete(`/spa/commission-settlement/delete?id=${id}`);
}


/** 导出提成结算 */
export function exportCommissionSettlement(params: any) {
  return requestClient.download('/spa/commission-settlement/export-excel', { params });
}

